home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 4223 < prev    next >
Encoding:
Text File  |  1996-08-06  |  2.4 KB  |  87 lines

  1. Path: newsbf02.news.aol.com!not-for-mail
  2. From: jasoncone@aol.com (Jason Cone)
  3. Newsgroups: comp.lang.c++
  4. Subject: DLL Trouble
  5. Date: 28 Jan 1996 23:29:54 -0500
  6. Organization: America Online, Inc. (1-800-827-6364)
  7. Sender: root@newsbf02.news.aol.com
  8. Message-ID: <4ehig2$7d3@newsbf02.news.aol.com>
  9. Reply-To: jasoncone@aol.com (Jason Cone)
  10. NNTP-Posting-Host: newsbf02.mail.aol.com
  11.  
  12. I am trying to use Turbo C++ Visual Edition for Windows to write a DLL
  13. which contains a single exportable function called rolldice.  I want to
  14. call this function from within a Paradox for Windows 4.5 form.
  15.  
  16. In Paradox, I have used the form's USES window to specify the DLL as
  17. follows:
  18.  
  19. Uses DICE  ; dice.dll
  20.    rolldice(sides CWORD, qty CWORD) CWORD
  21. endUses
  22.  
  23. Paradox calls the function like this:
  24.  
  25. method pushButton(var eventInfo Event)
  26.     var
  27.         i, rolled SmallInt
  28.     endVar
  29.  
  30.     for i from 1 to 6
  31.         rolled = rolldice(6,3) ; <--- CALLED HERE
  32.         switch
  33.          case i = 1 : STR.value = rolled
  34.          case i = 2 : INT.value = rolled
  35.          case i = 3 : WIS.value = rolled
  36.          case i = 4 : DEX.value = rolled
  37.          case i = 5 : CON.value = rolled
  38.          case i = 6 : CHA.value = rolled
  39.        endSwitch
  40.     endFor    
  41. endmethod
  42.  
  43.  
  44.  
  45. Following is the C/C++ code for the DLL:
  46.  
  47. #include <stdlib.h>
  48. #include <time.h>
  49. #include <windows.h>
  50.  
  51. int far pascal _export rolldice(int, int);
  52.  
  53. int far pascal _export rolldice(int sides, int qty)
  54. {
  55.    int result = 0;
  56.  
  57.    for (int i = 0; i < qty; i++)
  58.       result += (random(sides) + 1);
  59.    return result;
  60. }
  61.  
  62. int FAR PASCAL LibMain(HANDLE hInstance, WORD wDataSeg, WORD cbHeapSize,
  63. LPSTR lpCmdLine);
  64.  
  65. int FAR PASCAL LibMain(HANDLE hInstance, WORD wDataSeg, WORD cbHeapSize,
  66. LPSTR lpCmdLine){
  67.    return 1;
  68. }
  69.  
  70. I compile this code as a DLL using the Large Memory model, Explicit
  71. Functions Exported, targeted for Windows 3.1 or greater, Static Runtime
  72. Library.  It compiles fine, giving me warnings that the four LibMain
  73. parameters are never used.
  74.  
  75. However, when I try to run my Paradox form, I get an error which says that
  76. "This form references external procedures or DLLs which could not be
  77. found."   I believe the problem is locating the "external procedures" not
  78. the DLL itself, as I've tried moving the DLL around between Windows,
  79. Windows\System, and the form's working directory.
  80.  
  81. I can't figure out what I'm doing wrong.
  82.  
  83. Oh, I'm running Windows 95, if that makes any difference.
  84.  
  85. Please email any response to JasonCone@aol.com
  86. Thanks!
  87.